import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router =  new Router({
    mode:'history',
    base:'/',
    routes: [
        {
            path: '/',
            component: (resolve) => { require(['../components/index.vue'], resolve) },
            name: 'index',
            meta: {requireAuth: false}
        },
        // {
        //     path: '/',
        //     component: (resolve) => { require(['../components/home.vue'], resolve) },
        //     redirect: '/index',
        //     meta: {requireAuth: false},
        //     children: [

        //     ]
        // },
        {
            path: '/medical_history',
            component: (resolve) => { require(['../components/medical_history.vue'], resolve) },
            name: 'medical_history',
            meta: {requireAuth: false}
        },
        {
            path: '/physical_exam',
            component: (resolve) => { require(['../components/physical_exam.vue'], resolve) },
            name: 'physical_exam',
            meta: {requireAuth: false}
        },
        {
            path: '/2week_drugused',
            component: (resolve) => { require(['../components/2week_drugused.vue'], resolve) },
            name: '2week_drugused',
            meta: {requireAuth: false}
        },
        {
            path: '/carotid_doppler',
            component: (resolve) => { require(['../components/carotid_doppler.vue'], resolve) },
            name: 'carotid_doppler',
            meta: {requireAuth: false}
        },
        {
            path: '/ecg_check',
            component: (resolve) => { require(['../components/ecg_check.vue'], resolve) },
            name: 'ecg_check',
            meta: {requireAuth: false}
        },
        {
            path: '/family_history',
            component: (resolve) => { require(['../components/family_history.vue'], resolve) },
            name: 'family_history',
            meta: {requireAuth: false}
        },
        {
            path: '/lab_check_cerebralstroke_est',
            component: (resolve) => { require(['../components/lab_check_cerebralstroke_est.vue'], resolve) },
            name: 'lab_check_cerebralstroke_est',
            meta: {requireAuth: false}
        },
        {
            path: '/vasdis_operationdetail',
            component: (resolve) => { require(['../components/vasdis_operationdetail.vue'], resolve) },
            name: 'vasdis_operationdetail',
            meta: {requireAuth: false}
        },
        
    ]
})

router.beforeEach((to, from, next) => {
    if(to.meta.requireAuth){
        if(window.localStorage.getItem('token') == null||window.localStorage.getItem('token')== ''||window.localStorage.getItem('token')== undefined){
            next({path:'/'})
        }else{
            next()
        }
    }else{
        next()
    }
})
export default router
